/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#ifndef SERVERLOGIC_HPP
#define SERVERLOGIC_HPP

#include "Server.hpp"

namespace spelprog2 {
namespace net {
namespace server_logic {

//! Base class for server logic.
class ServerLogic : public net::NetMessageListener {
protected:
    Server & server_;
    ServerLogic(Server & server) : net::NetMessageListener(), server_(server) { }
};


//! Handles LoginRequest messages.
struct HandleLogin : public ServerLogic {
    HandleLogin(Server & server) : ServerLogic(server) { }
    virtual void onMessage(MessagePtr msg, const NetMessageInfo & info);
};


//! Base class for commands that require a log in to be handled. (Else they are discarded.)
struct Authorizer : public ServerLogic {
    Authorizer(Server & server) : ServerLogic(server) { }
    virtual void onMessage(MessagePtr msg, const NetMessageInfo & origin);
    virtual void onAuthedMessage(MessagePtr msg, const NetMessageInfo & info) = 0;
};


//! Simply passes on messages to Server's primary registry.
struct PassOn : public Authorizer {
    PassOn(Server & server) : Authorizer(server) { }
    virtual void onAuthedMessage(MessagePtr msg, const NetMessageInfo & info);
};


//! For dealing with requests from clients to change vars.
struct HandleVarChange : public Authorizer {
    HandleVarChange(Server & server) : Authorizer(server) { }
    virtual void onAuthedMessage(MessagePtr msg, const NetMessageInfo & info);
};


}; //namespace server_logic
}; //namespace net
}; //namespace spelprog2

#endif //SERVERLOGIC_HPP